<?php 
/**
 * Xử lý thêm manufacture mới
 */
 $man = NULL;
 if(isset($_GET['id'])){
    $man = $Bus->Manufacture->getItemById($_GET['id']);
    if(!$man){
        $url = url('errors','404');
        redirect($url);
    }
 }else{
    $url = url('errors','404');
    redirect($url);
 }
if(isset($_POST['btSubmit'])){
    $data = array(
        'idmanufactures'     => $_GET['id'],
        'manufactures_name'  => $_POST['txtName'],
        'manufactures_status'=> $_POST['slStatus']
    );
    if(!empty($_FILES['fLogo'])){
        $data['manufactures_logo'] = "images/".$_FILES['fLogo']['name'];
    }
    $mDto = new Dto_Table("manufactures", $mysql, $data);
    
    $error = $Bus->Manufacture->updateManufacture($mDto, $_FILES['fLogo']);
    if(empty($error)){
        $message = "Cập nhật thành công";
    }    
}

include 'component/header.php';
include 'component/slidebar.php'; 
?>
<!-- BEGIN CONTENT -->
<div id="content">
    <div class="box-out">
    	<div class="box-in">
    		<div class="box-head"><h1>Cập nhật nhà sản xuất...</h1></div>
    		<div class="box-content">
                <?php if(isset($error)) {?>
                <div class="notification error">
    				<div class="messages"><?php echo $error; ?><div class="close"><img src="css/images/icon/close.png" alt="close" /></div></div>
    			</div><!-- end div .notification error -->
                <?php }?>
                <?php if(isset($message)){?>
                <div class="notification success">
				    <div class="messages" >
                        <?php echo $message;?> 
                        <a href="/?mod=admin&act=mans-manager">Click vào đây</a> 
                        để về trang quản lý nhà sản xuất 
                        <div class="close"><img src="css/images/icon/close.png" alt="close" /></div>
                    </div>
    			</div><!-- end div .notification success -->
                <?php }?>
    			<div class="form">
    				<form action="" method="post" enctype="multipart/form-data" >
    					<fieldset>
    						<label for="small_field">Tên nhà sản xuất</label>
    						<input type="text" class="text small" name="txtName" value="<?php echo $man->manufactures_name;?>" />
    						<label for="upload_field">Logo nhà sản xuất</label>
                            <p><img src="<?php echo $man->manufactures_logo;?>" width="170" height="170" /></p>
    						<input type="file" class="file" name="fLogo" />
                            <label for="select_field">Select field</label>
    						<select class="text" id="select_field" name="slStatus">
    							<option value="0" <?php echo ($man->manufactures_status)?"":"selected=selected";?>>Enable</option>
    							<option value="1" <?php echo ($man->manufactures_status)?"selected='selected'":"";?>>Disable</option>
    						</select>
    						<hr />
    						<input type="submit" value="Cập nhật lại" class="submit" name="btSubmit" />
                            <a class="submit" href="/?mod=admin&act=mans-manager">Trang quản lý nhà sản xuất</a>
    					</fieldset>
    				</form>
    			</div><!-- end div .form -->
    		</div><!-- end div .box-content -->
    	</div><!-- end div .box-in -->
</div><!-- end div #content -->
<!-- END CONTENT -->

<?php
include 'component/footer.php'; 
?>
